package com.scau402.system1.controller;

import com.scau402.common.core.domain.AjaxResult;
import com.scau402.common.core.page.TableDataInfo;
import com.scau402.system1.domain.dto.WmsCreateAdjustBoundOrderDTO;
import com.scau402.system1.domain.query.WmsAdjustBoundOrderQuery;
import com.scau402.system1.service.IWmsAdjustBoundOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;

/**
 * 库存调整单控制器
 * @since 2024/1/29
 */
// TODO: 根据DDD重构接口结构
@RestController
@RequestMapping("/system/adjustOrder")
public class WmsAdjustBoundOrderController {
    @Autowired
    private IWmsAdjustBoundOrderService wmsAdjustBoundOrderService;

    /**
     * 获取库存调整单列表
     * @return 结果
     * @since 2024/1/29
     */
    @PreAuthorize("@ss.hasPermi('system:adjustBound:query')")
    @PostMapping("/list")
    public TableDataInfo listAdjustBoundOrder(@RequestBody WmsAdjustBoundOrderQuery query){
        return wmsAdjustBoundOrderService.listAdjustBoundOrder(query);
    }

    /**
     * 创建库存调整单
     * @param createOrder 需要调整的货品列表
     * @return 结果
     * @since 2024/1/29
     */
    @PreAuthorize("@ss.hasPermi('system:adjustBound:create')")
    @PostMapping("/create")
    public AjaxResult createAdjustBoundOrder(@Validated @RequestBody WmsCreateAdjustBoundOrderDTO createOrder){
        return wmsAdjustBoundOrderService.createAdjustBoundOrder(createOrder);
    }

    /**
     * 获取库存调整单详情
     * @return 结果
     * @since 2024/1/29
     */
    @PreAuthorize("@ss.hasPermi('system:adjustBound:detail')")
    @GetMapping("/detail")
    public AjaxResult getAdjustBoundOrderDetail(@RequestParam Long adjustOrderId){
        return wmsAdjustBoundOrderService.getAdjustBoundOrderDetail(adjustOrderId);
    }

    /**
     * 获取翡翠详情
     * @return 结果
     * @since 2024/1/29
     */
    @PreAuthorize("@ss.hasPermi('system:adjustBound:jade:detail')")
    @GetMapping("/jade/detail")
    public AjaxResult getJadeDetail(@RequestParam @NotBlank(message = "翡翠条码不能为空") String barcode){
        return wmsAdjustBoundOrderService.getJadeDetail(barcode);
    }

    /**
     * 获取调整人员名称与id
     * @return
     */
    @GetMapping("/employee")
    public AjaxResult getAdjustEmployee(){
        return wmsAdjustBoundOrderService.getAdjustEmployee();
    }

    /**
     * 获取盘点单号列表
     * @return
     */
    @GetMapping("/checkOrderCode")
    public AjaxResult getCheckOrderCode(){
        return wmsAdjustBoundOrderService.getCheckOrderCode();
    }
}
